package com.kikcn.demo.services;

import com.kikcn.demo.dao.ArticleRepository;
import com.kikcn.demo.domain.Article;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import javax.annotation.Resource;
import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;

/**
 * User: Administrator
 * Date: 2015/3/12
 * Time: 21:49
 */
@Service
public class ArticleServiceImpl implements IArticleService {
    @Resource
    private ArticleRepository articleRepository;

    @Transactional
    public void save(Article article) {
        this.articleRepository.save(article);
    }

    @Override
    public Page<Article> list(Pageable page) {
        Page<Article> data = articleRepository.findAll(page);
        return data;
    }

    @Override
    public void delete(Article article) {
        articleRepository.delete(article);
    }

    @Override
    public void delete(Integer id) {
        articleRepository.delete(id);
    }

    @Override
    public void update(Article article) {
        articleRepository.save(article);
    }

    @Override
    public Article findOne(Integer id) {
        return articleRepository.findOne(id);
    }

    @Override
    public long count() {
        return articleRepository.count();
    }
}
